<?php /** @noinspection PhpMixedReturnTypeCanBeReducedInspection */

declare(strict_types=1);

namespace DreamCat\ControllerParamGen\Decoder;

use DreamCat\ControllerParamGen\HttpBodyDecodeInterface;
use JetBrains\PhpStorm\Pure;

/**
 * form消息体解码
 * @author vijay
 */
class FormBodyDecoder implements HttpBodyDecodeInterface
{
    /**
     * @inheritDoc
     */
    #[Pure]
    public function match(string $contentType): bool
    {
        return str_contains($contentType, "application/x-www-form-urlencoded");
    }

    /**
     * @inheritDoc
     */
    public function parseBody(string $bodyText): array
    {
        parse_str($bodyText, $body);
        return $body;
    }
}

# end of file
